{include file="public/layout" /}
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body web-system" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">提问标题</label>
                            <div class="layui-input-inline">
                                {$info.ask_title|htmlspecialchars_decode}
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">问题描述</label>
                            <div class="layui-input-inline">
                                {$info.content|htmlspecialchars_decode}
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">回答内容</label>
                            <div class="layui-input-inline">
                                <textarea id="content" name="content" class="layui-textarea" placeholder=""  style="width: 75%;padding:0px 0px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">审核</label>
                            <div class="layui-input-inline w70">
                                <input type="checkbox" lay-filter="is_review" lay-skin="switch" lay-text="是|否" checked >
                                <input type="hidden" name="is_review" value="1" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="ask_id" value="{$info.ask_id}">
                                <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        window.UEDITOR_HOME_URL = "__ROOT_DIR__/public/plugins/Ueditor/";
    </script>
    {eju:static file="/public/plugins/Ueditor/ueditor.config.js"/}
    {eju:static file="/public/plugins/Ueditor/ueditor.all.min.js"/}
    {eju:static file="/public/plugins/Ueditor/lang/zh-cn/zh-cn.js"/}
    <script type="text/javascript">
        UE.getEditor('content',{
            serverUrl :"{:url('user/Uploadify/index',array('savepath'=>'weapp'))}",
            zIndex: 999,
            initialFrameWidth: "135%", //初化宽度
            initialFrameHeight: 300, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999,
            removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
            pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: false,
            toolbars: [["forecolor", "backcolor", "removeformat", "|", "simpleupload", "unlink"]],
        });
        //必须在提交前渲染编辑器；
        function content() {
            //判断编辑模式状态:0表示【源代码】HTML视图；1是【设计】视图,即可见即所得；-1表示不可用
            if(UE.getEditor("content").queryCommandState('source') != 0) {
                UE.getEditor("content").execCommand('source'); //切换到【设计】视图
            }
        }
    </script>
    <script>
        layui.config({
            base: '__SKIN__/' //静态资源所在路径
            ,version: '{$version}'
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'set'], function(){
            var $ = layui.$
                ,layer = layui.layer
                ,form = layui.form;

            // 监听开关
            form.on('switch', function(data){
                var elemId = data.elem.attributes['lay-filter']['nodeValue'];
                if (data.elem.checked) {
                    this.value = 1;
                } else {
                    this.value = 0;
                }
                $("input[name='"+elemId+"']").val(this.value);
            });
            //监听提交
            form.on('submit(formSubmit)', function(data){
                var load = layer_loading();
                data.field._ajax = 1;
                var content = UE.getEditor("content").getContent();
                data.field.content = content;
                $.ajax({
                    type : 'post',
                    url : "{:url('Answer/add')}",
                    data : data.field,
                    dataType : 'json',
                    success : function(res){
                        layer.close(load); //关闭loading
                        if(res.code == 1){
                            layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                parent.gourl(res.url);
                            });
                        }else{
                            showErrorMsg(res.msg);
                        }
                    },
                    error: function(e){
                        layer.close(load); //关闭loading
                        showErrorAlert();
                    }
                });
                return false;
            });

        });

    </script>
    {include file="public/footer" /}